package 离婚登记数和粗离婚率之比.Bean;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class DivorceAnalysisBean1 implements Writable {
    private float divorceCount;//离婚登记数
    private long populationCount;//总人口
    private double divorceRate;

    public DivorceAnalysisBean1() {
    }

    // 全参构造函数，方便初始化对象并赋值
    public DivorceAnalysisBean1(float divorceCount, long populationCount, double divorceRate) {
        this.divorceCount = divorceCount;
        this.populationCount = populationCount;
        this.divorceRate = divorceRate;
    }

    public void set(float divorceCount, long populationCount) {
        this.divorceCount = divorceCount;
        this.populationCount = populationCount;
    }

    public void set(float divorceCount,double divorceRate) {
        this.divorceCount = divorceCount;
        this.divorceRate = divorceRate;
    }


    // Getter和Settejr方法

    public float getDivorceCount() {
        return divorceCount;
    }

    public void setDivorceCount(float divorceCount) {
        this.divorceCount = divorceCount;
    }

    public long getPopulationCount() {
        return populationCount;
    }

    public void setPopulationCount(long populationCount) {
        this.populationCount = populationCount;
    }

    public double getDivorceRate() {
        return divorceRate;
    }

    public void setDivorceRate(double divorceRate) {
        this.divorceRate = divorceRate;
    }

    @Override
    public String toString() {

        return "离婚登记对数：" + divorceCount + "\t" + "粗离婚率：" + divorceRate + "%";
    }

    // 重写write方法，将对象数据序列化输出

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeFloat(divorceCount);
        dataOutput.writeLong(populationCount);
        dataOutput.writeDouble(divorceRate);
    }

    // 重写readFields方法，从输入流反序列化数据填充对象属性
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.divorceCount = dataInput.readFloat();
        this.populationCount = dataInput.readLong();
        this.divorceRate = dataInput.readDouble();
    }
}
